<?php

namespace common\app;

use yii\helpers\Url;
use Yii;
use cm;

class Am
{

    //**********************************************车型库
    function carBrand()
    {
        $data = [];
        $url = "http://www.51macc.com:8080/Mattrio/SelectCar/Manufacture";
        $pdata = array("year" => '');
        $resStr = Cm::$curl->post($url, $pdata);
        $resArr = json_decode($resStr, true);
        if (isset($resArr['all'])) {
            $list = [];
            foreach ($resArr['all'] as $item) {
                $latter = self::getFirstCharter($item[1]);
                $img = $this->carBrandLogo($item[1]);
                $list[] = array("id" => $item[1], "name" => $item[1], 'latter' => $latter, 'img' => $img);
            }

            $sort = array(
                'direction' => 'SORT_ASC', //排序顺序标志 SORT_DESC 降序；SORT_ASC 升序
                'field' => 'latter',       //排序字段
            );
            $arrSort = array();
            foreach ($list AS $uniqid => $row) {
                foreach ($row AS $key => $value) {
                    $arrSort[$key][$uniqid] = $value;
                }
            }
            if ($sort['direction']) {
                array_multisort($arrSort[$sort['field']], constant($sort['direction']), $list);
            }

            $newList = array();
            foreach ($list as $row) {
                $newList[$row['latter']][] = $row;
            }
            $data = $newList;
        }
        return $data;
    }

    function carSeries($brand)
    {
        $data = [];
        $url = "http://www.51macc.com:8080/Mattrio/SelectCar/VehicleName";
        $pdata = array("year" => '', "Manufacture" => $brand);
        $resStr = Cm::$curl->post($url, $pdata);
        $resArr = json_decode($resStr, true);
        if (is_array($resArr)) {
            $list = [];
            foreach ($resArr as $item) {
                $list[] = array("id" => $item['Vehicle_Name_CN'], "name" => $item['Vehicle_Name_CN']);
            }
            $data = $list;
        }
        return $data;
    }

    function carMl($brand, $series)
    {
        $data = [];
        $url = "http://www.51macc.com:8080/Mattrio/SelectCar/Nameofsales";
        $pdata = array("year" => '', "Manufacture" => $brand, "VehicleName" => $series);
        $resStr = Cm::$curl->post($url, $pdata);
        $resArr = json_decode($resStr, true);
        if (is_array($resArr)) {
            $list = [];
            foreach ($resArr as $item) {
                $list[] = array("id" => $item['Name_of_sales'], "name" => $item['Name_of_sales']);
            }
            $data = $list;
        }
        return $data;
    }

    function carYear($brand, $series, $ml)
    {
        $data = [];
        $url = "http://www.51macc.com:8080/Mattrio/SelectCar/Years";
        $pdata = array("Manufacture" => $brand, "VehicleName" => $series, "Nameofsales" => $ml);
        $resStr = Cm::$curl->post($url, $pdata);
        $resArr = json_decode($resStr, true);
        if (is_array($resArr)) {
            $list = [];
            foreach ($resArr as $item) {
                $list[] = array("id" => $item['year'], "name" => $item['year']);
            }
            $data = $list;
        }
        return $data;
    }

    function carInfo($brand, $series, $ml, $year)
    {
        $data = [];
        $url = "http://www.51macc.com:8080/Mattrio/SelectCar/QueryCar";
        $pdata = array("Manufacture" => $brand, "VehicleName" => $series, "Nameofsales" => $ml, "year" => $year, 'userid' => $this->appkey());
        $resStr = Cm::$curl->post($url, $pdata);
        $resArr = json_decode($resStr, true);
        if (isset($resArr['list'])) {
            foreach ($resArr['list'] as $item) {
                $data[] = $item;
            }
        }
        return $data;
    }

    //**********************************************//

    //**********************************************保养件
    function wearingPartsCategory()
    {
        $data = [];
        $url = "http://www.51macc.com:8080/MattrioManager/AftermarketBrandController/getProductsCategory";
        $resStr = Cm::$curl->post($url, ['']);
        $resArr = json_decode($resStr, true);
        if (isset($resArr['list'])) {
            foreach ($resArr['list'] as $item) {
                $data[] = array("id" => $item['category_id'], "name" => $item['category_name']);
            }
        }
        return $data;
    }

    function wearingPartsBrand($cateID)
    {
        $data = [];
        $url = "http://www.51macc.com:8080/MattrioManager/AftermarketBrandController/getProductsBrand";
        $resStr = Cm::$curl->post($url, ['category_id' => $cateID]);
        $resArr = json_decode($resStr, true);
        if (isset($resArr['list'])) {
            foreach ($resArr['list'] as $item) {
                $data[] = array("id" => $item['brand_category_id'], "name" => $item['brand_name']);
            }
        }
        return $data;
    }

    function wearingPartsBrandProducts($brand_category_ids)
    {
        $data = ['products' => []];
        $url = "http://www.51macc.com:8080/MattrioManager/AftermarketBrandController/getProducts";
        $resStr = Cm::$curl->post($url, ['brand_category_ids' => $brand_category_ids]);
        $resArr = json_decode($resStr, true);
        if (isset($resArr['list'])) {
            foreach ($resArr['list'] as $item) {
                $data['products'][] = array(
                    "type" => $item['product_id'],
                    "name" => $item['other'],
                    "category_id" => $item['brand_category_id'],
                    "brand" => $item['brand_name'],
                    "img" => $item['brand_img']
                );
            }
        }
        return $data;
    }

    function queryByOEOrType($key)
    {

        $url = "http://www.51macc.com:8080/Mattrio/OeInterface/queryOenumber";
        $resStr = Cm::$curl->post($url, ['oenumber' => $key, 'userid' => $this->appkey()]);
        return $resStr;

        $data = [];
        $url = "http://www.51macc.com:8080/Mattrio/OeApi/getOeCategory";
        $resStr = Cm::$curl->post($url, ['part_number' => $key, 'userid' => $this->appkey()]);
        $resArr = json_decode($resStr, true);
        if (isset($resArr['list'])) {
            foreach ($resArr['list'] as $item) {
                $data[] = array(
                    "type" => $item['part_number'],
                    "name" => $item['part_name'],
                    "category_id" => $item['category_id'],
                    "category_name" => $item['category_name'],
                    "price" => $item['price']
                );
            }
        }
        return $resArr;
    }

    function wearingPartsProducts($mikey, $cateID)
    {
        $data = ['oes' => [], 'products' => []];
        $url = "http://www.51macc.com:8080/Mattrio/OeInterface/queryPrductOfCategory";
        $resStr = Cm::$curl->post($url, ['mikey' => $mikey, 'category_id' => $cateID, 'userid' => $this->appkey()]);
        //echo $resStr;exit;
        $resArr = json_decode($resStr, true);
        if (isset($resArr['oes']) && isset($resArr['products'])) {
            foreach ($resArr['oes'] as $item) {
                $data['oes'][] = array("number" => $item['oe_numbers'], "name" => $item['category_name']);
            }

            foreach ($resArr['products'] as $item) {
                $data['products'][] = array(
                    "type" => $item['product_id'],
                    "name" => $item['other'],
                    "brand" => $item['brand_name'],
                    "img" => $item['brand_img']
                );
            }
        }
        return $data;
    }

    //**********************************************//

    function vehiclePartsCategory($parentID = 0, $level = 1)
    {
        $userID = $this->appkey();
        $data = [];
        switch ($level) {
            case 1:
                $data[] = ["id" => "A", "name" => "底盘部分"];
                $data[] = ["id" => "B", "name" => "发动机与变速器"];
                $data[] = ["id" => "C", "name" => "车身部分"];
                $data[] = ["id" => "D", "name" => "电器及照明系统"];
                $data[] = ["id" => "E", "name" => "内外饰部分"];
                $data[] = ["id" => "F", "name" => "工具"];
                $data[] = ["id" => "G", "name" => "辅料项目"];
                break;
            case 2:
                $url = "http://www.51macc.com:8080/Mattrio/ProductInterface/getCategory2";
                $pdata = array("categoryid" => $parentID, "mikey" => '', "userid" => $userID);
                $resStr = Cm::$curl->post($url, $pdata);
                $resArr = json_decode($resStr, true);
                if (isset($resArr['list'])) {
                    foreach ($resArr['list'] as $item) {
                        $data[] = array("id" => $item['category_id'], "name" => $item['category_name']);
                    }
                }
                break;
            case 3:
                $url = "http://www.51macc.com:8080/Mattrio/ProductInterface/getCategory3";
                $pdata = array("categoryid" => $parentID, "mikey" => '', "userid" => $userID);
                $resStr = Cm::$curl->post($url, $pdata);
                $resArr = json_decode($resStr, true);
                if (isset($resArr['list'])) {
                    foreach ($resArr['list'] as $item) {
                        $data[] = array("id" => $item['category_id'], "name" => $item['category_name']);
                    }
                }
                break;
        }
        return $data;
    }

    function vehiclePartsList($mikey, $key = '')
    {
        $key = empty($key) ? ' ' : $key;
        $data = [];
        $url = "http://www.51macc.com:8080/Mattrio/ProductInterface/LikeQueryOes";
        $resStr = Cm::$curl->post($url, ['like_name' => $key, 'mikey' => $mikey, 'userid' => $this->appkey()]);
        $resArr = json_decode($resStr, true);
        if (isset($resArr['list'])) {
            foreach ($resArr['list'] as $item) {
                $data[] = array(
                    "parent_name" => $item['parent_name'],
                    'oe' => $item['oe_numbers'],
                    "name" => $item['category_name'],
                    'remark'=>(isset($item['name1'])?$item['name1']:'').' '.(isset($item['note_parts'])?$item['note_parts']:'')
                );
            }
        }
        return $data;
    }

    function vin($vin)
    {
        $data=[];
        $url="http://www.51macc.com:8080/Mattrio/VinInterface/query_vin";
        $resStr = Cm::$curl->post($url, ['vin' => $vin, 'userid' => $this->appkey()]);
        $resArr = json_decode($resStr, true);
        if (isset($resArr['list'])) {
            $data=$resArr['list'][0];
        }
        return $data;
    }

    //网站接口
    function CarCommond($mikey)
    {
        $data = ['has_byj' => false, 'has_qcj' => false, 'has_by' => false, 'has_epc' => false];
        $url = "http://www.51macc.com:8080/Mattrio/CarInterface/CheckButton";
        $resStr = Cm::$curl->post($url, ['mikey' => $mikey]);
        $resArr = json_decode($resStr, true);
        if (isset($resArr['btns'])) {
            $arr = explode('<\/p>', $resArr['btns']);
            foreach ($arr as $item) {
                if (strpos($item, '保养件') !== false) {
                    if (strpos($item, 'lastbtn') !== false && strpos($item, 'lastbtn2') === false)
                        $data['has_byj'] = true;
                }
                if (strpos($item, '全车件') !== false) {
                    if (strpos($item, 'lastbutton') !== false && strpos($item, 'lastbutton2') === false)
                        $data['has_qcj'] = true;
                }
                if (strpos($item, '保养周期') !== false) {
                    if (strpos($item, 'cyclebtn') !== false && strpos($item, 'cyclebtn2') === false)
                        $data['has_by'] = true;
                }
                if (strpos($item, 'Magic-EPC') !== false) {
                    if (strpos($item, 'epcbtn') !== false && strpos($item, 'epcbtn2') === false)
                        $data['has_epc'] = true;
                }
            }
        }
        return $data;
    }

    //网站接口 车型适配的保养件分类
    function CarWearingcate($mikey)
    {
        $imgUrl = 'http://mattrio-car-img.oss-cn-shanghai.aliyuncs.com/category/';
        $data = [];
        $url = "http://www.51macc.com:8080/Mattrio/OeInterface/getByCategorys";
        //$resStr = Cm::$curl->post($url, ['mikey' => $mikey, 'userid' => $this->appkey()],'GET');
        $resStr = Cm::$curl->get($url . '?mikey=' . $mikey);

        $resArr = json_decode($resStr, true);
        if (isset($resArr['Categorys'])) {
            foreach ($resArr['Categorys'] as $item) {
                $data[] = ["id" => $item['category_id'], "name" => $item['category_name'], "img" => $imgUrl . $item['img']];
            }
        }
        return $data;
    }

    //网站接口 车型适配保养件分类的配件列表
    function CarWearingCateParts($mikey, $categoryID)
    {
        $data = [];
        $url = "http://www.51macc.com:8080/Mattrio/OeInterface/queryPrductOfCategory";
        $resStr = Cm::$curl->post($url, ['mikey' => $mikey, 'category_id' => $categoryID, 'userid' => $this->appkey()]);
        $resArr = json_decode($resStr, true);

        if (isset($resArr['oes']) && isset($resStr['products'])) {
            $oes = [];
            $products = [];
            foreach ($resArr['oes'] as $item) {
                $oes[] = array("number" => $item['oe_numbers'], "name" => $item['category_name']);
            }
            foreach ($resArr['products'] as $item) {
                $oes[] = array(
                    "type" => $item['product_id'],
                    "name" => $item['other'],
                    "brand" => $item['brand_name'],
                    "img" => $item['brand_img']
                );
            }
            $data['oes'] = $oes;
            $data['products'] = $products;
        }
    }

    //网站接口 查询OE
    function queryOe($oe)
    {
        $data = [];
        $url="http://www.51macc.com:8080/Mattrio/OeInterface/queryOenumber";
        $resStr = Cm::$curl->post($url, ['oenumber' => $oe, 'userid' => $this->appkey()]);
        $resArr = json_decode($resStr, true);

        if (isset($resArr['list'])) {
            foreach ($resArr['list'] as $item) {
                $data[] = array(
                    "parent_name" => $item['parent_name'],
                    'oe' => $item['oe_numbers'],
                    "name" => $item['category_name'],
                    'remark'=>(isset($item['name1'])?$item['name1']:'').' '.(isset($item['note_parts'])?$item['note_parts']:'')
                );
            }
        }
        return $data;
    }


    private function appkey()
    {
        return Yii::$app->params['51macc-key'];
    }

    private static function getFirstCharter($s0)
    {
        $fchar = ord($s0{0});
        if ($s0 == '讴歌(进口)')
            return 'O';

        if ($fchar >= ord("A") and $fchar <= ord("z")) return strtoupper($s0{0});
        //$s1 = iconv("UTF-8","gb2312//IGNORE", $s0);
        // $s2 = iconv("gb2312","UTF-8//IGNORE", $s1);
        $s1 = self::get_encoding($s0, 'GB2312');
        $s2 = self::get_encoding($s1, 'UTF-8');
        if ($s2 == $s0) {
            $s = $s1;
        } else {
            $s = $s0;
        }
        $asc = ord($s{0}) * 256 + ord($s{1}) - 65536;
        if ($asc >= -20319 and $asc <= -20284) return "A";
        if ($asc >= -20283 and $asc <= -19776) return "B";
        if ($asc >= -19775 and $asc <= -19219) return "C";
        if ($asc >= -19218 and $asc <= -18711) return "D";
        if ($asc >= -18710 and $asc <= -18527) return "E";
        if ($asc >= -18526 and $asc <= -18240) return "F";
        if ($asc >= -18239 and $asc <= -17923) return "G";
        if ($asc >= -17922 and $asc <= -17418) return "H";
        if ($asc >= -17417 and $asc <= -16475) return "J";
        if ($asc >= -16474 and $asc <= -16213) return "K";
        if ($asc >= -16212 and $asc <= -15641) return "L";
        if ($asc >= -15640 and $asc <= -15166) return "M";
        if ($asc >= -15165 and $asc <= -14923) return "N";
        if ($asc >= -14922 and $asc <= -14915) return "O";
        if ($asc >= -14914 and $asc <= -14631) return "P";
        if ($asc >= -14630 and $asc <= -14150) return "Q";
        if ($asc >= -14149 and $asc <= -14091) return "R";
        if ($asc >= -14090 and $asc <= -13319) return "S";
        if ($asc >= -13318 and $asc <= -12839) return "T";
        if ($asc >= -12838 and $asc <= -12557) return "W";
        if ($asc >= -12556 and $asc <= -11848) return "X";
        if ($asc >= -11847 and $asc <= -11056) return "Y";
        if ($asc >= -11055 and $asc <= -10247) return "Z";
        return '';
    }

    private static function get_encoding($data, $to)
    {
        $encode_arr = array('UTF-8', 'ASCII', 'GBK', 'GB2312', 'BIG5', 'JIS', 'eucjp-win', 'sjis-win', 'EUC-JP');
        $encoded = mb_detect_encoding($data, $encode_arr);
        $data = mb_convert_encoding($data, $to, $encoded);
        return $data;
    }

    public function carBrandLogo($brand)
    {
        $url = 'http://mattrio-car-img.oss-cn-shanghai.aliyuncs.com/car_icon/';
        $str = '{
"RECORDS":[
{
"parent_name":"DS(长安标致雪铁龙)",
"car_icon":"DS.jpg"
},
{
"parent_name":"GMC",
"car_icon":null
},
{
"parent_name":"MINI(进口)",
"car_icon":"MINI.jpg"
},
{
"parent_name":"SMART(进口)",
"car_icon":"smart.jpg"
},
{
"parent_name":"一汽",
"car_icon":"yiqi.jpg"
},
{
"parent_name":"一汽(吉林)",
"car_icon":"yiqi.jpg"
},
{
"parent_name":"万丰",
"car_icon":"wanfeng.jpg"
},
{
"parent_name":"三菱(东南)",
"car_icon":"sanling.jpg"
},
{
"parent_name":"三菱(北京奔驰)",
"car_icon":"sanling.jpg"
},
{
"parent_name":"三菱(广汽三菱)",
"car_icon":"sanling.jpg"
},
{
"parent_name":"三菱(进口)",
"car_icon":"sanling.jpg"
},
{
"parent_name":"上汽大通",
"car_icon":"shangqidatongMAXUS.jpg"
},
{
"parent_name":"上海汇众",
"car_icon":"huizhong.jpg"
},
{
"parent_name":"世爵汽车",
"car_icon":null
},
{
"parent_name":"东南(东南汽车)",
"car_icon":"dongnan.jpg"
},
{
"parent_name":"东风",
"car_icon":"dongfeng.jpg"
},
{
"parent_name":"东风(东风小康)",
"car_icon":"dongfengxiaokang.jpg"
},
{
"parent_name":"东风风度",
"car_icon":"dongfengfengdu.jpg"
},
{
"parent_name":"东风风神",
"car_icon":"dongfengfengshen.jpg"
},
{
"parent_name":"东风风行",
"car_icon":"dongfengfengxing.jpg"
},
{
"parent_name":"中兴",
"car_icon":"zhongxing.jpg"
},
{
"parent_name":"中华(华晨中华)",
"car_icon":"zhonghua.jpg"
},
{
"parent_name":"中客华北",
"car_icon":null
},
{
"parent_name":"中顺汽车",
"car_icon":"zhongshun.jpg"
},
{
"parent_name":"丰田(一汽丰田)",
"car_icon":"fengtian.jpg"
},
{
"parent_name":"丰田(广汽丰田)",
"car_icon":"fengtian.jpg"
},
{
"parent_name":"丰田汽车(进口)",
"car_icon":"fengtian.jpg"
},
{
"parent_name":"九龙汽车",
"car_icon":"jiulong.jpg"
},
{
"parent_name":"云雀",
"car_icon":"yunque.jpg"
},
{
"parent_name":"五十铃(江西)",
"car_icon":"wushiling.jpg"
},
{
"parent_name":"五菱(上汽通用五菱)",
"car_icon":"wuling.jpg"
},
{
"parent_name":"众泰",
"car_icon":"zhongtai.jpg"
},
{
"parent_name":"保时捷(进口)",
"car_icon":"baoshijie.jpg"
},
{
"parent_name":"光冈汽车",
"car_icon":null
},
{
"parent_name":"克莱斯勒(东南汽车)",
"car_icon":"kelaisile.jpg"
},
{
"parent_name":"克莱斯勒(北京奔驰)",
"car_icon":"kelaisile.jpg"
},
{
"parent_name":"克莱斯勒(进口)",
"car_icon":"kelaisile.jpg"
},
{
"parent_name":"全球鹰(吉利)",
"car_icon":"jiliqiche.jpg"
},
{
"parent_name":"兰博基尼(进口",
"car_icon":"lanbojini.jpg"
},
{
"parent_name":"兰博基尼(进口)",
"car_icon":"lanbojini.jpg"
},
{
"parent_name":"凯翼汽车",
"car_icon":"kaiyi.jpg"
},
{
"parent_name":"凯迪拉克(上汽通用)",
"car_icon":"kaidilake.jpg"
},
{
"parent_name":"凯迪拉克(进口)",
"car_icon":"kaidilake.jpg"
},
{
"parent_name":"别克(上汽通用)",
"car_icon":"bieke.jpg"
},
{
"parent_name":"别克(进口)",
"car_icon":"bieke.jpg"
},
{
"parent_name":"力帆",
"car_icon":"lifan.jpg"
},
{
"parent_name":"劳斯莱斯(进口)",
"car_icon":"laosilaisi.jpg"
},
{
"parent_name":"北京汽车",
"car_icon":"beijing.jpg"
},
{
"parent_name":"北汽制造",
"car_icon":"beiqizhizao.jpg"
},
{
"parent_name":"北汽威旺",
"car_icon":"beiqiweiwang.jpg"
},
{
"parent_name":"北汽幻速",
"car_icon":"beiqihuansu.jpg"
},
{
"parent_name":"北汽新能源",
"car_icon":"beijing.jpg"
},
{
"parent_name":"华晨鑫源",
"car_icon":"SWMsiweiqiche.jpg"
},
{
"parent_name":"华普",
"car_icon":"huapu.jpg"
},
{
"parent_name":"华泰",
"car_icon":"huatai.jpg"
},
{
"parent_name":"华阳",
"car_icon":"0"
},
{
"parent_name":"华颂汽车",
"car_icon":"huasong.jpg"
},
{
"parent_name":"南京依维柯",
"car_icon":"yiweike.jpg"
},
{
"parent_name":"卡威汽车",
"car_icon":"kawei.jpg"
},
{
"parent_name":"卡尔森汽车",
"car_icon":null
},
{
"parent_name":"双环",
"car_icon":"shuanghuan.jpg"
},
{
"parent_name":"双龙(进口)",
"car_icon":"shuanglong.jpg"
},
{
"parent_name":"吉利",
"car_icon":"jiliqiche.jpg"
},
{
"parent_name":"吉奥",
"car_icon":"guangqijiao.jpg"
},
{
"parent_name":"吉普(北京奔驰)",
"car_icon":"Jeep.jpg"
},
{
"parent_name":"吉普(广汽菲克)",
"car_icon":"Jeep.jpg"
},
{
"parent_name":"吉普(进口)",
"car_icon":"Jeep.jpg"
},
{
"parent_name":"吉普（广汽菲克）",
"car_icon":"Jeep.jpg"
},
{
"parent_name":"名爵(上汽名爵)",
"car_icon":"MG.jpg"
},
{
"parent_name":"启辰",
"car_icon":"qichen.jpg"
},
{
"parent_name":"哈弗(长城)",
"car_icon":"hafu.jpg"
},
{
"parent_name":"哈飞",
"car_icon":"hafei.jpg"
},
{
"parent_name":"夏利(天津一汽)",
"car_icon":"yiqi.jpg"
},
{
"parent_name":"大众(一汽大众)",
"car_icon":"dazhong.jpg"
},
{
"parent_name":"大众(上汽大众)",
"car_icon":"dazhong.jpg"
},
{
"parent_name":"大众(进口)",
"car_icon":"dazhong.jpg"
},
{
"parent_name":"大发(一汽大发)",
"car_icon":"yiqi.jpg"
},
{
"parent_name":"大宇汽车",
"car_icon":null
},
{
"parent_name":"大迪",
"car_icon":"dadi.jpg"
},
{
"parent_name":"大金龙",
"car_icon":"haige.jpg"
},
{
"parent_name":"天汽美亚汽车",
"car_icon":"meiya.jpg"
},
{
"parent_name":"天马",
"car_icon":"tianma.jpg"
},
{
"parent_name":"奇瑞",
"car_icon":"qirui.jpg"
},
{
"parent_name":"奔腾(一汽)",
"car_icon":"benteng.jpg"
},
{
"parent_name":"奔驰(北京奔驰)",
"car_icon":"benchi.jpg"
},
{
"parent_name":"奔驰(福建奔驰)",
"car_icon":"benchi.jpg"
},
{
"parent_name":"奔驰(进口)",
"car_icon":"benchi.jpg"
},
{
"parent_name":"奥迪(一汽奥迪)",
"car_icon":"aodi.jpg"
},
{
"parent_name":"奥迪(进口)",
"car_icon":"aodi.jpg"
},
{
"parent_name":"如虎(进口)",
"car_icon":"0"
},
{
"parent_name":"威兹曼(进口)",
"car_icon":"weiziman.jpg"
},
{
"parent_name":"威麟(奇瑞)",
"car_icon":"weilin.jpg"
},
{
"parent_name":"安驰",
"car_icon":"jianghuai.jpg"
},
{
"parent_name":"宝沃",
"car_icon":"baowo.jpg"
},
{
"parent_name":"宝马(华晨宝马)",
"car_icon":"baoma.jpg"
},
{
"parent_name":"宝马(进口)",
"car_icon":"baoma.jpg"
},
{
"parent_name":"宝骏(上汽通用五菱)",
"car_icon":"baojun.jpg"
},
{
"parent_name":"宝龙",
"car_icon":"baolong.jpg"
},
{
"parent_name":"宾利(进口)",
"car_icon":"binli.jpg"
},
{
"parent_name":"富奇",
"car_icon":"fuqi.jpg"
},
{
"parent_name":"巴博斯(进口)",
"car_icon":"babosi.jpg"
},
{
"parent_name":"帕加尼汽车",
"car_icon":null
},
{
"parent_name":"帝豪(吉利)",
"car_icon":"jiliqiche.jpg"
},
{
"parent_name":"广州汽车",
"car_icon":"guangqichuanqi.jpg"
},
{
"parent_name":"广汽讴歌",
"car_icon":"ouge.jpg"
},
{
"parent_name":"庆铃",
"car_icon":"qingling.jpg"
},
{
"parent_name":"开瑞(奇瑞)",
"car_icon":"kairui.jpg"
},
{
"parent_name":"恒天汽车",
"car_icon":"hengtianqiche.jpg"
},
{
"parent_name":"悍马(进口)",
"car_icon":null
},
{
"parent_name":"悍马(进口)",
"car_icon":"hanma.jpg"
},
{
"parent_name":"成功汽车",
"car_icon":null
},
{
"parent_name":"扬子",
"car_icon":"liebaoqiche.jpg"
},
{
"parent_name":"捷豹(进口)",
"car_icon":"jiebao.jpg"
},
{
"parent_name":"斯威汽车",
"car_icon":null
},
{
"parent_name":"斯巴鲁(进口)",
"car_icon":"sibalu.jpg"
},
{
"parent_name":"斯柯达(上汽大众-斯柯达)",
"car_icon":"sikeda.jpg"
},
{
"parent_name":"斯柯达(进口)",
"car_icon":"sikeda.jpg"
},
{
"parent_name":"新凯",
"car_icon":"xinkai.jpg"
},
{
"parent_name":"新雅途",
"car_icon":"xinyatu.jpg"
},
{
"parent_name":"日产(东风日产)",
"car_icon":"richan.jpg"
},
{
"parent_name":"日产(进口)",
"car_icon":"richan.jpg"
},
{
"parent_name":"日产(郑州日产)",
"car_icon":"richan.jpg"
},
{
"parent_name":"昌河",
"car_icon":"changhe.jpg"
},
{
"parent_name":"本田(东风本田)",
"car_icon":"bentian.jpg"
},
{
"parent_name":"本田(广汽本田)",
"car_icon":"bentian.jpg"
},
{
"parent_name":"本田汽车(进口)",
"car_icon":"bentian.jpg"
},
{
"parent_name":"林肯(进口)",
"car_icon":"linken.jpg"
},
{
"parent_name":"标致(东风标致雪铁龙)",
"car_icon":"biaozhi.jpg"
},
{
"parent_name":"标致(进口)",
"car_icon":"biaozhi.jpg"
},
{
"parent_name":"欧宝(进口)",
"car_icon":"oubao.jpg"
},
{
"parent_name":"比亚迪",
"car_icon":"biyadi.jpg"
},
{
"parent_name":"比速汽车",
"car_icon":null
},
{
"parent_name":"永源",
"car_icon":"yongyuan.jpg"
},
{
"parent_name":"汉腾汽车",
"car_icon":"hanteng.jpg"
},
{
"parent_name":"江南",
"car_icon":"jiangnan.jpg"
},
{
"parent_name":"江淮",
"car_icon":"jianghuai.jpg"
},
{
"parent_name":"江铃",
"car_icon":"jiangling.jpg"
},
{
"parent_name":"沃尔沃(进口)",
"car_icon":"woerwo.jpg"
},
{
"parent_name":"沃尔沃(长安福特马自达)",
"car_icon":"woerwo.jpg"
},
{
"parent_name":"沃尔沃亚太",
"car_icon":"woerwo.jpg"
},
{
"parent_name":"法拉利(进口)",
"car_icon":"falali.jpg"
},
{
"parent_name":"海马(郑州)",
"car_icon":"haima.jpg"
},
{
"parent_name":"海马汽车",
"car_icon":"haima.jpg"
},
{
"parent_name":"特斯拉(进口)",
"car_icon":"tesila.jpg"
},
{
"parent_name":"猎豹(长丰猎豹)",
"car_icon":"liebaoqiche.jpg"
},
{
"parent_name":"玛莎拉蒂汽车(进口)",
"car_icon":"mashaladi.jpg"
},
{
"parent_name":"现代(北京现代)",
"car_icon":"xiandai.jpg"
},
{
"parent_name":"现代(进口)",
"car_icon":"xiandai.jpg"
},
{
"parent_name":"瑞麒(奇瑞)",
"car_icon":"ruiqi.jpg"
},
{
"parent_name":"知豆",
"car_icon":"zhidou.jpg"
},
{
"parent_name":"福汽启腾",
"car_icon":"fuqiqiteng.jpg"
},
{
"parent_name":"福特(江铃)",
"car_icon":"fute.jpg"
},
{
"parent_name":"福特(进口)",
"car_icon":"fute.jpg"
},
{
"parent_name":"福特(长安福特马自达)",
"car_icon":"fute.jpg"
},
{
"parent_name":"福田",
"car_icon":"futian.jpg"
},
{
"parent_name":"福迪汽车",
"car_icon":"fudi.jpg"
},
{
"parent_name":"科尼赛克",
"car_icon":null
},
{
"parent_name":"红旗(一汽)",
"car_icon":"hongqi.jpg"
},
{
"parent_name":"纳智捷(东风裕隆)",
"car_icon":"nazhijie.jpg"
},
{
"parent_name":"腾势",
"car_icon":"tengshi.jpg"
},
{
"parent_name":"英伦(吉利)",
"car_icon":"jiliqiche.jpg"
},
{
"parent_name":"英致",
"car_icon":"weichaiyingzhi.jpg"
},
{
"parent_name":"英菲尼迪(东风)",
"car_icon":"yingfeinidi.jpg"
},
{
"parent_name":"英菲尼迪(进口)",
"car_icon":"yingfeinidi.jpg"
},
{
"parent_name":"荣威(上汽荣威)",
"car_icon":"rongwei.jpg"
},
{
"parent_name":"莲花(进口)",
"car_icon":"lutesi.jpg"
},
{
"parent_name":"莲花汽车",
"car_icon":"lianhua.jpg"
},
{
"parent_name":"菲亚特(南京菲亚特)",
"car_icon":"feiyate.jpg"
},
{
"parent_name":"菲亚特(广汽菲亚特)",
"car_icon":"feiyate.jpg"
},
{
"parent_name":"菲亚特(进口)",
"car_icon":"feiyate.jpg"
},
{
"parent_name":"萨博",
"car_icon":null
},
{
"parent_name":"蔚来",
"car_icon":null
},
{
"parent_name":"西雅特(进口)",
"car_icon":"xiyate.jpg"
},
{
"parent_name":"观致",
"car_icon":"guanzhiqiche.jpg"
},
{
"parent_name":"解放",
"car_icon":"yiqi.jpg"
},
{
"parent_name":"讴歌(进口)",
"car_icon":"ouge.jpg"
},
{
"parent_name":"起亚(东风悦达起亚)",
"car_icon":"qiya.jpg"
},
{
"parent_name":"起亚(进口)",
"car_icon":"qiya.jpg"
},
{
"parent_name":"路虎(奇瑞)",
"car_icon":"jiebao.jpg"
},
{
"parent_name":"路虎(进口)",
"car_icon":"luhu.jpg"
},
{
"parent_name":"迈凯伦(进口)",
"car_icon":"maikailun.jpg"
},
{
"parent_name":"通家福",
"car_icon":"shanqitongjia.jpg"
},
{
"parent_name":"通田",
"car_icon":"tongtian.jpg"
},
{
"parent_name":"道奇(进口)",
"car_icon":"daoqi.jpg"
},
{
"parent_name":"野马汽车",
"car_icon":"yemaqiche.jpg"
},
{
"parent_name":"金杯(华晨金杯)",
"car_icon":"jinbei.jpg"
},
{
"parent_name":"金程汽车",
"car_icon":"jincheng.jpg"
},
{
"parent_name":"铃木(昌河铃木)",
"car_icon":"lingmu.jpg"
},
{
"parent_name":"铃木(进口)",
"car_icon":"lingmu.jpg"
},
{
"parent_name":"铃木(长安铃木)",
"car_icon":"lingmu.jpg"
},
{
"parent_name":"长城",
"car_icon":"zhangcheng.jpg"
},
{
"parent_name":"长安",
"car_icon":"zhangan.jpg"
},
{
"parent_name":"阿尔法·罗密欧",
"car_icon":null
},
{
"parent_name":"阿斯顿·马丁(进口)",
"car_icon":"asidun·mading.jpg"
},
{
"parent_name":"陆风(江铃)",
"car_icon":"lufeng.jpg"
},
{
"parent_name":"雪佛兰(上汽通用)",
"car_icon":"xuefolan.jpg"
},
{
"parent_name":"雪佛兰(上汽通用五菱)",
"car_icon":"xuefolan.jpg"
},
{
"parent_name":"雪佛兰(进口)",
"car_icon":"xuefolan.jpg"
},
{
"parent_name":"雪铁龙(东风标致雪铁龙)",
"car_icon":"xuetielong.jpg"
},
{
"parent_name":"雪铁龙(进口)",
"car_icon":"xuetielong.jpg"
},
{
"parent_name":"雷克萨斯(进口)",
"car_icon":"leikesasi.jpg"
},
{
"parent_name":"雷诺(东风)",
"car_icon":"leinuo.jpg"
},
{
"parent_name":"雷诺(进口)",
"car_icon":"leinuo.jpg"
},
{
"parent_name":"雷诺（东风）",
"car_icon":"leinuo.jpg"
},
{
"parent_name":"马自达(一汽马自达)",
"car_icon":"mazida.jpg"
},
{
"parent_name":"马自达(进口)",
"car_icon":"mazida.jpg"
},
{
"parent_name":"马自达(长安福特马自达)",
"car_icon":"mazida.jpg"
},
{
"parent_name":"黄海",
"car_icon":"huanghai.jpg"
},
{
"parent_name":"黑豹",
"car_icon":"heibao.jpg"
},
{
"parent_name":"齐星",
"car_icon":null
}
]
}';
        $img = '';
        $arr = json_decode($str, true);
        foreach ($arr['RECORDS'] as $item)
            if ($item['parent_name'] == $brand && !empty($item['car_icon']))
                $img = $url . $item['car_icon'];
        return $img;
    }
}

